home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 24
/
Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso
/
Aminet
/
dev
/
lang
/
PPCsmalltalk.lha
/
PPCSmallTalk
/
examples
/
primes.st
< prev
next >
Wrap
Text File
|
1986-10-19
|
618b
|
37 lines
Class Main
[
main
(Primes new) do: [:x | x print]
]
Class Primes
| primeGenerator lastFactor |
[
first
primeGenerator <- 2 to: 300.
lastFactor <- primeGenerator first.
^ lastFactor
|
next
primeGenerator <- (Factor new ;
remove: lastFactor
from: primeGenerator ).
^ lastFactor <- primeGenerator next.
]
Class Factor
| myFactor generator |
[
remove: factorValue from: generatorValue
myFactor <- factorValue.
generator <- generatorValue
|
next | possible |
[(possible <- generator next) notNil]
whileTrue:
[(possible \\ myFactor ~= 0)
ifTrue: [ ^ possible] ].
^ nil
]